/**
 * 
 */
package com.thor.palmmall.rest.device.repair.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SPictureConverter;
import com.thor.palmmall.rest.common.SSourceBillConverter;
import com.thor.palmmall.rest.device.repair.ADeviceRepair4Create;
import com.thor.palmmall.rest.repair.converter.SWorkOrderConverter;
import com.thor.palmmall.spi.device.repair.SDeviceRepair4Create;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SDeviceRepair4CreateConverter
    implements Converter<ADeviceRepair4Create, SDeviceRepair4Create> {

  public static SDeviceRepair4CreateConverter getInstance() {
    if (instance == null)
      instance = new SDeviceRepair4CreateConverter();
    return instance;
  }

  private static SDeviceRepair4CreateConverter instance;

  private SDeviceRepair4CreateConverter() {
  }

  @Override
  public SDeviceRepair4Create convert(ADeviceRepair4Create source) {
    if (source == null) {
      return null;
    }
    SDeviceRepair4Create target = new SDeviceRepair4Create();
    target.setStore(UCN.newInstance(source.getStore()));
    target.setApplicant(UCN.newInstance(source.getApplicant()));
    target.setCategory(UCN.newInstance(source.getCategory()));
    target.setRepairDate(source.getRepairDate());
    target.setTelephone(source.getTelephone());
    target.setSourceBill(SSourceBillConverter.getInstance().convert(source.getSourceBill()));
    target.setSituation(source.getSituation());
    target.setDevice(UCN.newInstance(source.getDevice()));
    target.setPlace(source.getPlace());
    target
        .setPictures(ConverterUtil.convert(source.getPictures(), SPictureConverter.getInstance()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    
    target.setType(source.getType());
    target.setWorkOrder(SWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setItems(new ArrayList<KV>());
    target.getItems().addAll(source.getItems());
    
    return target;
  }

}
